﻿@inject IConfiguration _configuration

<MudDrawerContainer Class="mud-height-full">
    <MudDrawer @bind-Open="IsOpen" Anchor="Anchor.Left" DisableOverlay="true" Elevation="8">
        <DrawerHeader Title="Settings" OnClose="CloseDrawer" DisplayDivider="true" />
        
        <MudTabs Elevation="2" Rounded="true" ApplyEffectsToContainer="true" PanelClass="pa-4" Style="height: 100%;" Class="custom-tabs">
            <MudTabPanel Icon="@Icons.Material.Filled.Person" Text="Profile">
                <ProfileForm/>
            </MudTabPanel>
            <MudTabPanel Icon="@CustomIcons.Puzzle" Text="Integrations">
                <IntegrationsForm />
            </MudTabPanel>
        </MudTabs>
        <MudPaper class="d-flex flex-row justify-center gap-2 pa-4" Style="@BackgroundColorStyle">
            <MudAvatar Size="Size.Medium">
                <MudImage Src="@AppLogoSmall" Alt="Stellar Chat logo"></MudImage>
            </MudAvatar>
            <MudText Class="my-auto" Color="Color.Primary">@AppName</MudText>
            <MudText Class="my-auto" Color="Color.Primary">
                <MudLink Class="my-auto" Color="Color.Primary" Href="@AppReleases" Target="_blank">@AppVersion</MudLink>
            </MudText>
        </MudPaper>
    </MudDrawer>
</MudDrawerContainer>

<style>
    .custom-tabs .mud-tabs-toolbar {
        background-color: @(_IsDarkModeEnabled ? "var(--mud-palette-surface)" : "#d6d3d1");
    }
</style>

@code 
{
    [Parameter]
    public bool IsOpen { get; set; }

    [Parameter]
    public EventCallback<bool> IsOpenChanged { get; set; }

    [CascadingParameter]
    private bool _IsDarkModeEnabled { get; set; }

    private string AppName => _configuration["app:name"] ?? string.Empty;
    private string AppVersion => _configuration["app:version"] ?? string.Empty;
    private string AppLogoSmall => _configuration["app:logoSmall"] ?? string.Empty;
    private string AppReleases => _configuration["app:releases"] ?? string.Empty;

    private string TabsBackgroundColorStyle => $"color: {(_IsDarkModeEnabled ? "var(--mud-palette-surface)" : "#d6d3d1")}; height: 100%;";
    private string BackgroundColorStyle => $"background-color: {(_IsDarkModeEnabled ? "#1e1f22" : "#d6d3d1")};";

    protected override async Task OnInitializedAsync()
    {
        await Task.CompletedTask;
    }

    private void CloseDrawer()
    {
        IsOpen = false;
        IsOpenChanged.InvokeAsync(IsOpen);
    }
}
